package com.ps.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ps.property.ResponseVO;
import com.ps.property.TOtherCollect;
import com.ps.service.CollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author gt
 * @类说明：
 * @date 2020/10/27 19:21
 */
@Api(tags = "收藏接口")
@Controller
@Validated
@Slf4j
public class ProvideCollectController {
    @Autowired
    CollectService collectService;

    @ApiOperation(value = "新增收藏信息接口",notes = "新增收藏信息接口，新增收藏")
    @PostMapping("/collectAdd-provide")
    @ResponseBody
    ResponseVO collectAdd(@Valid @RequestBody TOtherCollect tOtherCollect) {
        log.info("收藏提供者collectVo={}", tOtherCollect);

        int i = collectService.collectAdd(tOtherCollect);

        return ResponseVO.success(i);
    }

    @ApiOperation(value = "分页查询收藏信息接口")
    @ApiImplicitParams({@ApiImplicitParam(name = "currentPage", value = "当前页数", required = true),@ApiImplicitParam(name = "pageSize", value = "每页行数", required = true)})
    @GetMapping("/collectQuery-provide")
    @ResponseBody
    ResponseVO collectQuery(@RequestParam("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
        log.info("收藏提供者currentPage={}, pageSize={}",currentPage,pageSize);

        IPage<TOtherCollect> iPage = collectService.collectQuery(currentPage,pageSize);

        return ResponseVO.success(iPage);
    }

    @ApiOperation(value = "根据收藏id修改收藏信息接口")
    @ApiImplicitParam(name = "collectId",value = "收藏id",required = true)
    @PostMapping("/collectUpdate-provide")
    @ResponseBody
    ResponseVO collectUpdate(@Valid @RequestBody TOtherCollect tOtherCollect) {
        log.info("收藏提供者要修改的collectVo={}", tOtherCollect);

        int i = collectService.collectUpdate(tOtherCollect);

        return ResponseVO.success(i);
    }

    /**
     * 根据id修改状态
     * @param collectId
     * @param status
     * @return
     */
    @ApiOperation(value = "根据收藏id修改收藏状态接口")
    @ApiImplicitParams({@ApiImplicitParam(name = "collectId",value = "收藏id",required = true),@ApiImplicitParam(name = "status",value = "收藏状态",required = true)})
    @PostMapping("/collectUpdateByStatus-provide")
    @ResponseBody
    ResponseVO collectUpdateByStatus(int collectId, String status){
        log.info("收藏提供者要修改的id={},状态={}", collectId,status);

        return ResponseVO.success(collectService.collectUpdateByStatus(collectId,status));
    }

    @ApiOperation(value = "根据收藏ID查询收藏信息接口")
    @ApiImplicitParam(name = "collectId",value = "收藏id",required = true)
    @GetMapping("/collectQueryById-provide/{collectId}")
    @ResponseBody
    ResponseVO collectQueryById(@PathVariable int collectId) {
        log.info("收藏提供者要删除的collectId={}",collectId);

        TOtherCollect tOtherCollect = collectService.collectQueryById(collectId);

        return ResponseVO.success(tOtherCollect);
    }
}
